package com.qing.dish;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;

public class Demo2 {


    private static List<Dish> menu= Arrays.asList(
            new Dish("黄焖鸡米饭",false,15,"肉"),
            new Dish("水煮鱼",true,12,"鱼"),
            new Dish("酸菜鱼",false,20,"鱼"),
            new Dish("脆皮鸡米饭",false,18,"米饭"),
            new Dish("麻辣香锅",true,32,"米饭"),
            new Dish("鸡公煲",false,20,"肉"),
            new Dish("汉堡王",true,100,"米饭"),
            new Dish("至尊牛排",false,20,"肉"),
            new Dish("蛋炒饭",true,12,"素"),
            new Dish("咖喱",false,29,"米饭"),
            new Dish("炒白菜",false,8,"素"),
            new Dish("炒萝卜",false,9,"素"),
            new Dish("烤肉",true,50,"肉")
    );
    public static void main(String[] args) {
        if (menu.stream().anyMatch(Dish::isVegetarian)) {
            System.out.println("菜单存在素食！");
        }
        if(menu.stream().allMatch(dish -> dish.getCalories()<20)){
            System.out.println("所有的菜单价格都小于20");
        }

        if(menu.stream().noneMatch(dish -> dish.getCalories()<20)){
            System.out.println("最低消费大于20");
        }

        Optional<Dish> ex=menu.stream().filter((d)->{
            System.out.println(d.getName());
            return  d.isVegetarian();
        }).findAny();
        Dish dish=ex.get();
        System.out.println(dish);


        menu.stream().filter((d)->{
            System.out.println(d.getName());
            return  d.isVegetarian();
        }).findAny().ifPresent((Dish d)->{
            System.out.println(d.getName());
        });

        //给定一个数字列表，下面的代码能找出第一个平方能被3整除的数：
        List<Integer> someNumbers=Arrays.asList(1,2,3,4,5);
        someNumbers.stream().map(n->n*n).filter(n->n%3==0).findFirst().ifPresent(System.out::println);

    }
}
